module model.model;

import utils.log;

import model.imodel;
import project.project;
import vfs.recentcollector;

import vfs.jsonwriter;

import std.file;
import std.getopt;

class Model: IModel {
    static this() {
        ourInstance = new Model();
        Log.message("Create model");
    }

    private shared Project myProject;

    private this() {
    }

    private void parseCommandLine(string[] args) shared
    in {
        assert(args !is null);
    }
    body {
        string projectPath;
        getopt(args,
            "projectPath", &projectPath);
        if (projectPath !is null && exists(projectPath)) {
            myProject = new shared(Project)(projectPath);
        }
    }

    override package bool init(string[] args) shared {
        parseCommandLine(args);
        return true;
    }

    override package void run() shared {
        if (myProject !is null) {
            myProject.open();
        }
    }

    override public string getDefaultProjectConfiguration() const shared {
        return readText("config/defultProjectConfiguration.json");
    }

    override public shared(string)[] getRecentProjects() shared {
        return RecentCollector.getInstance().getRecentProjectsList();
    }
}
